#!/bin/bash

set -e          # exit on error
set -o pipefail # exit on pipeline error
set -u          # treat unset variable as error

. /minioslib || exit 1

SCRIPT_DIR="$(dirname "$(readlink -f "$0")")"

pkg update 
echo "icaclient       app_protection/install_app_protection   select  no" | debconf-set-selections -v
pkg install $SCRIPT_DIR/*.deb 
rm -f $SCRIPT_DIR/*.deb 

# Find the UID and GID of the user "citrixlog"
USER_ID=$(id -u citrixlog)
GROUP_ID=$(id -g citrixlog)

# Check if the user "citrixlog" exists
if [[ -z $USER_ID ]]; then
    echo "User 'citrixlog' does not exist."
    exit 1
fi

# Check if the group "citrixlog" exists
if [[ -z $GROUP_ID ]]; then
    echo "Group 'citrixlog' does not exist."
    exit 1
fi

# Replace the UID and GID with 2000
usermod -u 2000 citrixlog
groupmod -g 2000 citrixlog

# Check if the UID and GID were successfully changed
if [[ $? -eq 0 ]]; then
    echo "UID and GID of user 'citrixlog' have been changed to 2000."
else
    echo "Failed to change UID and GID of user 'citrixlog'."
    exit 1
fi

PACKAGE="icaclient"
echo "PACKAGE=$PACKAGE" >/.package
echo "VERSION=$(dpkg -s $PACKAGE | grep Version | sed 's/Version: //g' | sed 's/:/-/g')" >>/.package
